<?php

namespace app\index\controller;

use app\common\controller\IndexBaseController;
use think\facade\Db;

class Show extends IndexBaseController
{
    protected function initialize()
    {
        parent::initialize();
    }


    public function index()
    {
        $param = $this->request->get();
        if(empty($param['catedir'])){
            return '404';
        }
        if(empty($param['id'])){
            return '404';
        }
        $cate = Db::name('articles_cate')->where('dirname',$param['catedir'])->find();
        if(empty($cate)){
            return '404';
        }
        $mod = Db::name('articles_models')->find($cate['model_id']);
        $data = Db::name($mod['tablename'])->find($param['id']);
        if($data['is_show'] == 0){
            return '404';
        }
        
        $this->assign('cate', $cate);
        $cates = getCatePath($cate);
        foreach($cates as $k => $v){
            $this->assign('cate'.($k+1), $v);
        }
        
        $this->assign('mod', $mod);
        $this->assign('data', $data);

        if($data['areaid1']){
            $area1 = Db::name('area')->find($data['areaid1']);
            $this->assign('area1', $area1);
        }
        if($data['areaid2']){
            $area2 = Db::name('area')->find($data['areaid2']);
            $this->assign('area2', $area2);
        }
        if($data['areaid3']){
            $area3 = Db::name('area')->find($data['areaid3']);
            $this->assign('area3', $area3);
        }
        
        // if(!empty($data['adcode'])){
        //     $weather = getWeather($data['adcode']);
        //     $this->assign('weather', $weather);
        // }
        if(!empty($area1) && !empty($area2)){
            $weather = getWeather($area1['shortname'],$area2['shortname']);
            $this->assign('weather', $weather);
        }

        return  $this->fetch('/dianpu_show');
    }

}
